package com.zxy.demo.guava.concurrent;

import java.util.concurrent.*;

/**
 * Demo1.
 * 
 * Created by zxybird on 2018/1/22.
 */
public class Demo1 {

  public static void main(String[] args) {
    ExecutorService executorService = Executors.newSingleThreadExecutor();

    FutureTask<String> futureTask = new FutureTask<>(() -> {
      Thread.sleep(50000);
      return "test";
    });

    executorService.execute(futureTask);
    System.out.println("do other things1");

    try {
      futureTask.get(5000, TimeUnit.MILLISECONDS);

      System.out.println("do other things2");

    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (ExecutionException e) {
      e.printStackTrace();
    } catch (TimeoutException e) {
      e.printStackTrace();
    }

  }

}
